<template>
  <div class="comment-reply-container">
    <!-- 顶部导航 -->
    <van-nav-bar title="暂无回复" fixed>
      <template #left>
        <van-icon name="cross" @click="$emit('closeReply')"/>
      </template>
    </van-nav-bar>

    <!-- 展示文章评论 -->
    <comment-item :comment="comment"></comment-item>

    <!-- 全部回复单元格 -->
    <van-cell title="全部回复"></van-cell>

    <!-- 回复列表 -->
    <comment-list
      ref="comment-list"
      :sourceId="comment.com_id"
      idType="c"
    ></comment-list>

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        size="small"
        round
        class="btn"
        @click="isPostShow = true"
      >
        写评论
      </van-button>
    </div>

    <!-- 评论提交弹框 -->
    <van-popup
      v-model="isPostShow"
      position="bottom"
    >
      <comment-post
        :targetId="comment.com_id"
        :artId="$route.params.articleId"
        @postSuccess="postSuccessFn"
      ></comment-post>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      default: () => ({})
    }
  },

  data () {
    return {
      isPostShow: false // 写评论弹框状态
    }
  },
  methods: {
    // 发布评论成功后触发的方法
    postSuccessFn (newComment) {
      this.isPostShow = false

      this.$refs['comment-list'].addComment(newComment)
    }
  }
}
</script>

<style scoped lang="less">
.comment-reply-container {
  padding-top: 46px;
  padding-bottom: 44px;

  .reply-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 44px;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;

    .btn {
      width: 60%;
    }
  }
}
</style>
